package com.itheima.demo001;

public class PhoneTest {
    public static void main(String[] args) {
        //1.创建一个数组
        Phone[] arr = new Phone[3];

        //2.创建手机的对象
        Phone p1 = new Phone("华为荣耀",5000,"白色");
        Phone p2 = new Phone("苹果",10000,"粉色");
        Phone p3 = new Phone("小米",6000,"蓝色");

        //3.把手机对象，添加到数组中
        arr[0] = p1;
        arr[1] = p2;
        arr[2] = p3;

        //4.获取3部手机的平均价格
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            Phone phone = arr[i];
            sum = sum + phone.getPrice();
        }

        //5.求价格平均值
        //注意：数据尽量不要写死
        int avg = sum / arr.length;

        System.out.println(avg);
    }
}
